from multiprocessing import Queue, Process
import os,time,random
def writh(q):
    for value in ["a","b","c"]:
        print(f"将{value}写入Queue")
        q.put(value)
        time.sleep(random.random())
def read(q):
    while True:
        if not q.empty():
            value = q.get(True)
            print(f"从Queue中读取{value}")
            time.sleep(random.random())
        else:
            break
if __name__ == "__main__":
    q = Queue()
    p1 = Process(target=writh,args=(q,))
    p2 = Process(target=read,args=(q,))
    p1.start()
    p2.start()
    p1.join()
    p2.join()
    print("主进程")



